//示例 1:

//输入: numRows = 5
//输出: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]

// 涉及resize / operator[]
// 核心思想：找出杨辉三角的规律，发现每一行头尾都是1，中间第[j]个数等于上一行[j-1]+[j]
class Solution {
public:
	vector<vector<int>> generate(int numRows) {
		vector<vector<int>> vv;
		vv.resize(numRows);
		
		for(size_t i = 0; i < vv.size(); ++i)
		{
			vv[i].resize(i+1, 0);
			vv[i][0] = vv[i][vv[i].size() - 1] = 1;
		}
		
		for(size_t i = 0; i < vv.size(); ++i)
		{
			for(size_t j = 0; j < vv[i].size(); ++j)
			{
				if (vv[i][j] == 0)
				{
					vv[i][j] = vv[i-1][j] + vv[i-1][j-1];
				}
			}
		}
		
		return vv;
	}
};